Skip to content

feat(project_mcp): handle per-request MCP cancellation in start_repo_session#409

Merged
matt2e merged 1 commit intomainfrom
subagent-timeout
Mar 18, 2026
Merged

feat(project_mcp): handle per-request MCP cancellation in start_repo_session#409
matt2e merged 1 commit intomainfrom
subagent-timeout

Conversation

@matt2e
Copy link
Contributor

@matt2e matt2e commented Mar 18, 2026

Summary

  • Handle per-request cancellation tokens in start_repo_session to respond to MCP client CancelledNotification (e.g. Goose's 5-minute per-tool timeout)
  • When a per-request cancellation is received, cancel the child session to prevent orphaned sessions and return a structured cancelled outcome
  • Updates polling loop comments to reflect the dual cancellation token strategy

Test plan

  • Verify that Goose timeout triggers proper cancellation of the child session
  • Confirm parent project session cancellation still works as before
  • Check that the returned JSON {"outcome": "cancelled", "output": ""} is handled correctly by clients

🤖 Generated with Claude Code

…session

When Goose's 5-minute tool timeout fires, it sends a CancelledNotification
to the MCP server. rmcp 0.17 automatically cancels the RequestContext's
CancellationToken for that request. Previously, the start_repo_session
handler only watched self.cancel_token (the parent project session token)
and never noticed per-request cancellation, leaving child sessions running
as orphans after timeout.

Add the per-request CancellationToken as a parameter to start_repo_session
using rmcp's FromContextPart extractor (which extracts RequestContext.ct).
Add a new branch in the polling tokio::select! loop that watches this token
and cancels the child session via SessionRegistry::cancel when it fires.

The existing self.cancel_token branch is preserved for parent project
session cancellation. add_project_repo is not modified as it lacks a
similar long-running polling loop.
@matt2e matt2e requested review from baxen and wesbillman as code owners March 18, 2026 01:52
@matt2e matt2e merged commit 7177f35 into main Mar 18, 2026
4 checks passed
@matt2e matt2e deleted the subagent-timeout branch March 18, 2026 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant